<script setup>
import { computed } from "vue";
import { useStroe } from "./vuex";
const store = useStroe();

const add = () => {
  store.commit("increment", 2);
};

const count = computed(() => store.state.count);

const state = computed(() => store.state);

const userinfoName = computed({
  get: () => store.state.userinfo.name,
  set: (val) => store.commit("changeUserinfo", { name: val }),
});

const userinfoAge = computed({
  get: () => store.state.userinfo.age,
  set: (val) => store.commit("changeUserinfo", { age: val }),
});
</script>

<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <h1>
    vuex count: <span style="color: red"> {{ count }}</span>
  </h1>
  <button @click="add">increment</button>
  <p><input type="text" v-model="userinfoName" /></p>
  <p><input type="text" v-model="userinfoAge" /></p>
  <h2>state 数据</h2>
  <code> {{ state }} </code>
</template>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
